package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.BedDto;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/bed")
@Api(tags = "床位管理相关接口")
public class BedController extends BaseController {

    @Autowired
    private BedService bedService;

    @GetMapping("/read/room/{roomId}")
    @ApiOperation(value = "根据房间id查询床位", notes = "传入房间id")
    public ResponseResult<List<BedVo>> readBedByRoomId(@ApiParam(value = "房间ID", required = true) @PathVariable("roomId") Long roomId) {
        List<BedVo> beds = bedService.getBedsByRoomId(roomId);
        return success(beds);
    }

    @PostMapping("/create")
    @ApiOperation(value = "添加床位信息",notes = "传入床位信息")
    public ResponseResult addBed(@ApiParam("床位信息，包含床位编号，床位排序，和房间id")@RequestBody BedDto bedDto) {
        int count = bedService.addBed(bedDto);
        return toAjax(count);
    }

    //删除床位
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "根据床位id删除床位信息",notes = "根据床位id删除床位信息")
   /* @ApiImplicitParams({
            @ApiImplicitParam(name ="id",value = "传人床位id",required = true,dataType ="long")
    })*/
    public ResponseResult deleteBed(@ApiParam(value = "传人床位id", required = true) @PathVariable Long id) {
        int count = bedService.deleteBed(id);
        return toAjax(count);
    }

    //修改床位信息
    @PutMapping("/update")
    @ApiOperation("修改床位信息")
    public ResponseResult updateBed(@RequestBody BedDto bedDto) {
        bedService.updateBed(bedDto);
        return success();
    }

    //回显床位信息
    @GetMapping("/read/{id}")
    @ApiOperation(value = "回显床位信息", notes = "传入床位id")
    public ResponseResult<BedVo> readBed( @ApiParam("传入床位id" ) @PathVariable Long id) {

        BedVo bed = bedService.getBedById(id);
        return success(bed);

    }

}
